package com.workoutgrabber.model;

import java.util.Collections;
import java.util.List;

import org.jdom.Element;
import org.joda.time.DateTime;

public class WeightExercise extends Exercise {
	private List<ExerciseSet> sets;

	private WeightExercise(String name, DateTime date, List<ExerciseSet> sets){
		this.name = name;
		this.date = date;
		this.sets = sets;
	}
	
	public List<ExerciseSet> getExerciseSets() {
		return Collections.unmodifiableList(sets);
	}
	
	public static WeightExercise getInstance(String name, DateTime date, List<ExerciseSet> sets){
		return new WeightExercise(name, date, sets);
	}

	@Override
	public Element getAsXML() {
		Element exerciseElement = new Element("exercise");
		exerciseElement.setAttribute("type", "weightExercise");
		
		Element nameElement = new Element("name");
		nameElement.setText(this.name);
		
		Element dateElement = new Element("date");
		dateElement.setText(this.date.toString());
		
		Element setElement = new Element("sets");
		for (XMLable xml : sets) {
			setElement.addContent(xml.getAsXML());
		}
		
		exerciseElement.addContent(nameElement);
		exerciseElement.addContent(dateElement);
		exerciseElement.addContent(setElement);
		
		return exerciseElement;
	}
}
